package cn.lijiguo.concurrency.part1.states;

/**
 * NewRunnableTerminated
 * 展示线程的 NEW RUNNABLE TERMINATED 状态。
 *  即使线程正在运行，也是 RUNNABLE 状态，而不是 RUNNING 状态
 * @author lijiguo
 * @date 2020/1/6 14:42
 */
public class NewRunnableTerminated implements Runnable {

    public static void main(String[] args) {
        Thread t1 = new Thread(new NewRunnableTerminated(), "t1");
        // 打印出 NEW 状态
        System.out.println(t1.getState());
        t1.start();
        System.out.println(t1.getState());

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 打印出 RUNNABLE 状态，即使线程正在运行，也不是 RUNNING 状态
        System.out.println(t1.getState());

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 打印出 TERMINATED 状态
        System.out.println(t1.getState());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(Thread.currentThread().getName() + " : " + i);
        }
    }
}
